import 'package:excel_utils/utils/group_type.dart';

class CustomerBean {
  List<Data>? data;
  String? msg;
  int? status;

  CustomerBean({this.data, this.msg, this.status});

  CustomerBean.fromJson(Map<String, dynamic> json) {
    if (json['data'] != null) {
      data = <Data>[];
      json['data'].forEach((v) {
        data!.add(new Data.fromJson(v));
      });
    }
    msg = json['msg'];
    status = json['status'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.data != null) {
      data['data'] = this.data!.map((v) => v.toJson()).toList();
    }
    data['msg'] = this.msg;
    data['status'] = this.status;
    return data;
  }
}

class Data {
  String? bcCode;
  String? bcName;
  String? cmAddress;
  String? cmCode;
  String? cmContacts;
  String? cmEname;
  String? cmName;
  String? groupCode;
  String? groupName;
  dynamic cmMonthcost;
  int? cmOrdernum;
  dynamic cmOverfull;

  String? newCaseCode;
  dynamic newCmMonthcost;
  int?    newCmOrdernum;
  dynamic newCmOverfull;




  Data({
    this.bcCode,
    this.bcName,
    this.cmAddress,
    this.cmCode,
    this.cmContacts,
    this.cmEname,
    this.cmName,
    this.groupCode,
    this.groupName,
    this.newCaseCode,
    this.cmMonthcost,
    this.cmOrdernum,
    this.cmOverfull,
  });

  Data.fromJson(Map<String, dynamic> json) {
    bcCode = json['bcCode'];
    bcName = json['bcName'];
    cmAddress = json['cmAddress'].replaceAll("\n", "").replaceAll("\r", "").replaceAll("\t", "");
    cmCode = json['cmCode'];
    cmContacts = json['cmContacts'];
    cmEname = json['cmEname'];
    cmName = json['cmName'];
    groupCode = json['groupCode'];

    if (json['groupName'] != null) {
      var groupNameTemp = json['groupName'].toString();
      if (groupNameTemp.contains("GROUP")) {
        if (groupNameTemp == "A GROUP") {
          groupName = "CXC-A組";
        } else if (groupNameTemp == "B GROUP") {
          groupName = "CXC-B組";
        } else if (groupNameTemp == "C GROUP") {
          groupName = "CXC-C組";
        } else if (groupNameTemp == "D GROUP") {
          groupName = "CXC-D组";
        }
      }else{
        groupName = json['groupName'].toString();
      }
    }else{
      groupName = GroupType.getGroupName(cmCode.toString(), json['groupName']);
    }

    if(groupName == null || groupName == ""){
      groupName = json['bcName'];
    }

    newCaseCode = json['newCaseCode'];
    cmMonthcost = json['cmMonthcost'];
    cmOrdernum = json['cmOrdernum'];
    cmOverfull = json['cmOverfull'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['bcCode'] = this.bcCode;
    data['cmAddress'] = this.cmAddress;
    data['cmCode'] = this.cmCode;
    data['cmContacts'] = this.cmContacts;
    data['cmEname'] = this.cmEname;
    data['cmName'] = this.cmName;
    data['groupCode'] = this.groupCode;
    data['groupName'] = this.groupName;
    data['newCaseCode'] = this.newCaseCode;
    data['cmMonthcost'] = this.cmMonthcost;
    data['cmOrdernum'] = this.cmOrdernum;
    data['cmOverfull'] = this.cmOverfull;

    return data;
  }
}
